package com.wilmar.process.web.taglibs;

import java.io.IOException;

import javax.servlet.jsp.JspWriter;

import com.wilmar.process.enumerate.EnumProcessTagSupportPublicAttribute;

/**
 * @author asus
 * 
 */
public class ProcessInputTag extends ProcessTagSupport {

	/**
	 * 
	 */
	private static final long serialVersionUID = -5287455761366219580L;
	private String value;

	/**
	 * @see org.springframework.web.servlet.tags.RequestContextAwareTag#doStartTagInternal()
	 */
	protected int doStartTagInternal() throws Exception {
		String value_ = "";
		String type_ = "text";
		if (this.value != null && this.value.trim().length() != 0) {
			value_ = this.value;
		} else if (super.name != null && super.name.trim().length() != 0) {
			value_ = super.getAttribute(super.name);
		}
		StringBuffer html = new StringBuffer();
		html.append("<input type=\"");
		html.append(type_);
		html.append("\" value=\"");
		html.append(value_);
		html.append("\"");
		if (this.getId() != null) {
			html.append(" id=\"");
			html.append(this.getId());
			html.append("\"");
		}
		if (this.getName() != null) {
			html.append(" name=\"");
			html.append(this.getName());
			html.append("\"");
		}
		super.appendPublicAttribute(html,
				EnumProcessTagSupportPublicAttribute.CSSSTYLE);
		super.appendPublicAttribute(html,
				EnumProcessTagSupportPublicAttribute.CSSCLASS);
		super.appendPublicAttribute(html,
				EnumProcessTagSupportPublicAttribute.ONCLICK);
		if (this.getReadonly() != null) {
			html.append(" readonly=\"");
			html.append("readonly");
			html.append("\"");
		}
		html.append("/>");
		JspWriter outer = this.getOut();
		try {
			outer.write(html.toString());
		} catch (IOException e) {
			e.printStackTrace();
		}
		return SKIP_BODY;
	}

	public void setValue(String value) {
		this.value = value;
	}
}
